// pages/orderMgt/chooseEmploySend/chooseEmploySend.js
import Common from '../../../common/common.js';
let common = new Common;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list:[
        {uiid:1,name:'韵达快递',phone:15755136894},
        { uiid: 2, name: '顺丰快递', phone: 15755136894 },
        { uiid: 3, name: '中通快递', phone: 15755136894 },
      ],
      id:'',//物流公司id
    hidden:true,//隐藏弹框
    codeVal:'',//快递单号
    item:{},
    orderId:'',
    type:''
  },
  // 获取选择物流公司
  radioChange: function (e) {
    let id = e.detail.value;
    let list = this.data.list;
    for(var i = 0;i<list.length;i++){
      if (list[i].uuid==id){
          this.setData({
            item: list[i]
          })
      }
    }
    console.log(this.data.item)
    this.setData({
      id: e.detail.value
    })
    console.log(e.detail.value)
  },
  // 显示弹框
  sureWuLiu:function(e){
    if (!this.data.id){
      wx.showToast({
        title: '请选择快递公司',
        icon: 'none',
      })
      return;
    }else{
      this.setData({
        hidden: false,
      })
    }
    
  },
  scanCode: function (e) {
    var that = this;
    wx.scanCode({
      success: (res) => {
        that.setData({
          codeVal: res.result,
          scan: e.currentTarget.dataset.scan
        })
      }
    })
  },
  // 物流单号
  getVal:function(e){

    this.setData({
      codeVal:e.detail.value.replace(/[\W]/g,'')
    })
  },
  // 确定物流公司
  getcode:function(e){
    console.log(e)
    let type = e.currentTarget.dataset.fhcode
    if(type!=1){
      this.setData({
        hidden:true
      })
    }else{
      if (this.data.codeVal){
        console.log(this.data.codeVal)
        console.log(this.data.item)

        wx.setStorageSync('wuliuData', {
          wuliuid:this.data.id,
          wuliuname:this.data.item.name,
          wuliuphone:this.data.item.phone,
          wuliuno: this.data.codeVal
        })

        wx.navigateBack()
        
        //return;
        // wx.redirectTo({
        //   url: '/pages/orderMgt/orderInfo/orderInfo?wuliuid=' + this.data.id + '&wuliuname=' + this.data.item.name + '&wuliuphone=' + this.data.item.phone + '&type=' + this.data.type + '&id=' + this.data.orderId + '&wuliuno=' + this.data.codeVal +'&psType='+3,
        // })
      }else{
        wx.showToast({
          title: '请输入物流单号',
          icon:'none'
        })
        return;
      }
    }
  },
  // 查询物流公司
  getWuliuList:function(e){
    common.requestAjax('/api/trade-service/v1/myorder/queryDeliveryInfo', 'POST').then(res => {
      if (res.data.code == 1) {
        console.log(res)
        this.setData({
          list: res.data.records
        })
      }
    }).catch(err => {
      console.log(err);
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderId:options.orderId,
      type:options.type
    })
    this.getWuliuList();
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },



})